# -*- coding: utf-8 -*-
# @Time: 2021/8/2 11:39
# @Author: moxinqian
# @Contact: tel 18382469064
# @File: problem-2.py
# @DESC:

class Node(object):
    def __init__(self, val, next=None):
        self.val = val
        self.next = next


def reverseList(head):
    print("********")
    pre = None
    cur = head
    nHead = None
    while (cur):
        tmp = cur.next
        if tmp is None:
            nHead = cur
        cur.next = pre
        pre = cur
        cur = tmp
    return nHead


def iterNode(head):
    while (head):
        cur = head
        print(cur.val)
        head = head.next


if __name__ == "__main__":
    head = Node(1)
    head.next = Node(2)
    head.next.next = Node(3)
    head.next.next.next = Node(4)
    iterNode(head)

    # 反转
    rs =  reverseList(head)
    print("**********")
    iterNode(rs)
